package com.opensistemas.spm.model;

import org.appfuse.model.BaseObject;

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

import java.io.Serializable;

@Entity
@Table(name="workflow_unit",catalog="spm")
public class WorkflowUnit extends BaseObject implements Serializable {
    private Long id;
    private Workflow workflow;
    private Date startDate;
    private Date endDate;
    private Float duration;

    @Id  @GeneratedValue(strategy = GenerationType.AUTO)    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="workflow_id", nullable=false)
    public Workflow getWorkflow() {
        return this.workflow;
    }
    
    public void setWorkflow(Workflow workflow) {
        this.workflow = workflow;
    }
    
    @Column(name="start_date", nullable=false, length=0)
    public Date getStartDate() {
        return this.startDate;
    }
    
    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }
    
    @Column(name="end_date", nullable=false, length=0)
    public Date getEndDate() {
        return this.endDate;
    }
    
    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }
    
    @Column(name="duration", precision=12, scale=0)
    public Float getDuration() {
        return this.duration;
    }
    
    public void setDuration(Float duration) {
        this.duration = duration;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        WorkflowUnit pojo = (WorkflowUnit) o;

        if (workflow != null ? !workflow.equals(pojo.workflow) : pojo.workflow != null) return false;
        if (startDate != null ? !startDate.equals(pojo.startDate) : pojo.startDate != null) return false;
        if (endDate != null ? !endDate.equals(pojo.endDate) : pojo.endDate != null) return false;
        if (duration != null ? !duration.equals(pojo.duration) : pojo.duration != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (workflow != null ? workflow.hashCode() : 0);
        result = 31 * result + (startDate != null ? startDate.hashCode() : 0);
        result = 31 * result + (endDate != null ? endDate.hashCode() : 0);
        result = 31 * result + (duration != null ? duration.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("workflow").append("='").append(getWorkflow()).append("', ");
        sb.append("startDate").append("='").append(getStartDate()).append("', ");
        sb.append("endDate").append("='").append(getEndDate()).append("', ");
        sb.append("duration").append("='").append(getDuration()).append("'");
        sb.append("]");
      
        return sb.toString();
    }

}
